package com.argticling.controller;

import com.argticling.model.Article;
import com.argticling.model.DublinCore;
import com.argticling.service.ArticleService;
import com.argticling.service.FeedBuilderService;
import com.sun.syndication.io.FeedException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("/feed")
public class FeedController extends MultiActionController {
   
    /*@Autowired
    private FeedBuilderService feedService;
    
    @Autowired
    private ArticleService articleService;
*/
    //significa que del lado de la URL voy a ir a localhost/feed/feed
    @RequestMapping(value = "/feed", method = RequestMethod.GET)
    public ModelAndView seeAllArticle(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView mav = new ModelAndView("feeds/feed");
        try {
            mav.addObject("xml", feedService.getFeedXML(articleService.getAllArticles()));
        } catch (FeedException e) {
            mav.addObject("xml", "Ha ocurrido un error...");//todo ver de meter en formado feed
            e.printStackTrace();
        }
        return mav;
    }

}